home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1996 June / MACPOWER-1996-06.ISO.7z / MACPOWER-1996-06.ISO / AMUG / PROGRAMING_7 / AntiAliasMan 2.0 / AntiAliasMan / AntiAliasManTester.c < prev    next >
C/C++ Source or Header  |  1996-02-01  |  6KB  |  282 lines

  1. #include "AntiAliasMan.h"
  2.  
  3. void        ToolBoxInit(void);
  4. void        MenuBarInit(void);
  5. void        WindowInit(void);
  6. void        EventLoop(void);
  7. void        DoEvent(EventRecord *eventPtr);
  8. void        HandleMouseDown(EventRecord *eventPtr);
  9. void        HandleMenuChoice(long menuChoice);
  10. void        DoUpdate(WindowPtr window);
  11.  
  12. WindowPtr    gWind;
  13.  
  14. void        main(void)
  15. {
  16.     ToolBoxInit();
  17.     MenuBarInit();
  18.     WindowInit();
  19.     AntiAliasManInit();
  20.  
  21.     EventLoop();
  22. }
  23.  
  24. void        ToolBoxInit(void)
  25. {
  26.     InitGraf(&qd.thePort);
  27.     InitWindows();
  28.     InitFonts();
  29.     InitMenus();
  30.     TEInit();
  31.     InitDialogs(nil);
  32.     InitCursor();
  33. }
  34.  
  35. void        MenuBarInit(void)
  36. {
  37.     Handle        menuBar;
  38.     MenuHandle    menu;
  39.  
  40.     menuBar=GetNewMBar(128);
  41.     SetMenuBar(menuBar);
  42.  
  43.     menu=GetMHandle(128);
  44.     AddResMenu(menu,'DRVR');
  45.     DisableItem(menu,1);
  46.  
  47.     DrawMenuBar();
  48. }
  49.  
  50. void        WindowInit(void)
  51. {
  52.     Rect    place;
  53.  
  54.     SetRect(&place,0,20,640,480);
  55.     gWind=NewCWindow(nil,&place,"¥p",true,4,(WindowPtr)-1L,true,0L);
  56. }
  57.  
  58. void        EventLoop(void)
  59. {
  60.     EventRecord    event;
  61.  
  62.     while(1)
  63.     {
  64.         while(!WaitNextEvent(everyEvent,&event,10L,nil));
  65.         DoEvent(&event);
  66.     }
  67. }
  68.  
  69. void        DoEvent(EventRecord *eventPtr)
  70. {
  71.     char        theChar;
  72.     WindowPtr    window;
  73.  
  74.     switch(eventPtr->what)
  75.     {
  76.         case mouseDown:
  77.             HandleMouseDown(eventPtr);
  78.             break;
  79.         case keyDown:
  80.         case autoKey:
  81.             theChar=eventPtr->message &charCodeMask;
  82.             if(eventPtr->modifiers &cmdKey) HandleMenuChoice(MenuKey(theChar));
  83.             break;
  84.         case updateEvt:
  85.             window=(WindowPtr)eventPtr->message;
  86.             DoUpdate(window);
  87.             break;
  88.     }
  89. }
  90.  
  91. void        HandleMouseDown(EventRecord *eventPtr)
  92. {
  93.     WindowPtr    whichWindow;
  94.     short        thePart;
  95.     long        menuChoice;
  96.     Point        thePt;
  97.  
  98.     thePart=FindWindow(eventPtr->where,&whichWindow);
  99.     switch(thePart)
  100.     {
  101.         case inMenuBar:
  102.             menuChoice=MenuSelect(eventPtr->where);
  103.             HandleMenuChoice(menuChoice);
  104.             HiliteMenu(false);
  105.             break;
  106.         case inSysWindow:
  107.             SystemClick(eventPtr,whichWindow);
  108.             break;
  109.         case inContent:
  110.             SetPort(whichWindow);
  111.             SelectWindow(whichWindow);
  112.             thePt=eventPtr->where;
  113.             GlobalToLocal(&thePt);
  114.             break;
  115.     }
  116. }
  117.  
  118. void        HandleMenuChoice(long menuChoice)
  119. {
  120.     short        menu,item;
  121.     Str255        dAName;
  122.     MenuHandle    appleMenu;
  123.     GrafPtr        savePort;
  124.  
  125.     menu=HiWord(menuChoice);
  126.     item=LoWord(menuChoice);
  127.  
  128.     switch(menu)
  129.     {
  130.         case 128:
  131.             if(item==1);
  132.             else
  133.             {
  134.                 appleMenu=GetMHandle(128);
  135.                 GetPort(&savePort);
  136.                 GetItem(appleMenu,item,dAName);
  137.                 OpenDeskAcc(dAName);
  138.                 SetPort(savePort);
  139.             }
  140.             break;
  141.         case 129:
  142.             if(item==1)
  143.             {
  144.                 CloseWindow(FrontWindow());
  145.                 if(FrontWindow()==nil)
  146.                 {
  147.                     appleMenu=GetMHandle(129);
  148.                     DisableItem(appleMenu,1);
  149.                 }
  150.             }
  151.             if(item==2) ExitToShell();
  152.             break;
  153.         case 130:
  154.             break;
  155.     }
  156. }
  157.  
  158. void        DoUpdate(WindowPtr window)
  159. {
  160.     Rect            place;
  161.     short            i;
  162.     OSErr            err;
  163.     long            time;
  164.     Str255            timestr;
  165.  
  166.     BeginUpdate(window);
  167.     SetPort(window);
  168.     if(window==gWind)
  169.     {
  170.         time = TickCount();
  171.  
  172.         ForeColor(blackColor);
  173.         MoveTo(10,40);
  174.         TextFont(20);
  175.         TextSize(12);
  176.         err = DrawAAString( "¥pAntialiased" );
  177.         TextSize(48);
  178.         err = DrawAAString( "¥p Text." );
  179.         MoveTo(10,80);
  180.         TextSize(12);
  181.         DrawString( "¥pQuickdraw" );
  182.         TextSize(48);
  183.         DrawString( "¥p Text." );
  184.  
  185.         SetRect(&place,20,200,100,280);
  186.         BackColor(redColor);
  187.         ForeColor(blueColor);
  188.         err = EraseAARoundRect(&place,20,20);
  189.         OffsetRect(&place,81,0);
  190.         EraseRoundRect(&place,20,20);
  191.  
  192.         OffsetRect(&place,81,0);
  193.         err = PaintAAOval(&place);
  194.         OffsetRect(&place,81,0);
  195.         PaintOval(&place);
  196.         OffsetRect(&place,81,0);
  197.         err = InvertAAArc(&place,180,45);
  198.         OffsetRect(&place,81,0);
  199.         InvertArc(&place,180,45);
  200.         SetRect(&place,14,290,587,355);
  201.         err = InvertAARoundRect(&place,20,20);
  202.         SetRect(&place,15,300,40,345);
  203.         for(i=0;i<22;i++)
  204.         {
  205.             err = InvertAAOval(&place);
  206.             OffsetRect(&place,26,0);
  207.         }
  208.         MoveTo(20,300);
  209.         err = AALineTo(120,320);
  210.         err = AALineTo(20,310);
  211.         err = AALineTo(580,310);
  212.         err = AALineTo(400,345);
  213.         err = AALineTo(300,320);
  214.         SetRect(&place,14,390,587,455);
  215.         InvertRoundRect(&place,20,20);
  216.         SetRect(&place,15,400,40,445);
  217.         for(i=0;i<22;i++)
  218.         {
  219.             InvertOval(&place);
  220.             OffsetRect(&place,26,0);
  221.         }
  222.         MoveTo(20,400);
  223.         LineTo(120,420);
  224.         LineTo(20,410);
  225.         LineTo(580,410);
  226.         LineTo(400,445);
  227.         LineTo(300,420);
  228.         SetRect(&place,200,20,250,70);
  229.         err = FrameAARoundRect(&place,20,20);
  230.         OffsetRect(&place,51,0);
  231.         err = PaintAARoundRect(&place,20,20);
  232.         OffsetRect(&place,51,0);
  233.         err = EraseAARoundRect(&place,20,20);
  234.         OffsetRect(&place,51,0);
  235.         err = InvertAARoundRect(&place,20,20);
  236.         OffsetRect(&place,51,0);
  237.         err = FillAARoundRect(&place,20,20,0L);
  238.         SetRect(&place,200,71,250,121);
  239.         FrameRoundRect(&place,20,20);
  240.         OffsetRect(&place,51,0);
  241.         PaintRoundRect(&place,20,20);
  242.         OffsetRect(&place,51,0);
  243.         EraseRoundRect(&place,20,20);
  244.         OffsetRect(&place,51,0);
  245.         InvertRoundRect(&place,20,20);
  246.         OffsetRect(&place,51,0);
  247.         FillRoundRect(&place,20,20,0L);
  248.         TextSize(15);
  249.  
  250.         ForeColor( greenColor );
  251.         MoveTo(225-StringWidth("¥pFrame")/2,15);
  252.         err = DrawAAString("¥pFrame");
  253.         MoveTo(276-StringWidth("¥pPaint")/2,15);
  254.         err = DrawAAString("¥pPaint");
  255.         MoveTo(327-StringWidth("¥pErase")/2,15);
  256.         err = DrawAAString("¥pErase");
  257.         MoveTo(378-StringWidth("¥pInvert")/2,15);
  258.         err = DrawAAString("¥pInvert");
  259.         MoveTo(429-StringWidth("¥pFill")/2,15);
  260.         err = DrawAAString("¥pFill");
  261.  
  262.         MoveTo(225-StringWidth("¥pFrame")/2,135);
  263.         DrawString("¥pFrame");
  264.         MoveTo(276-StringWidth("¥pPaint")/2,135);
  265.         DrawString("¥pPaint");
  266.         MoveTo(327-StringWidth("¥pErase")/2,135);
  267.         DrawString("¥pErase");
  268.         MoveTo(378-StringWidth("¥pInvert")/2,135);
  269.         DrawString("¥pInvert");
  270.         MoveTo(429-StringWidth("¥pFill")/2,135);
  271.         DrawString("¥pFill");
  272.  
  273.         NumToString( TickCount() - time, timestr );
  274.         ForeColor( blackColor );
  275.         MoveTo( 20, 190 );
  276.         TextSize( 14 );
  277.         DrawAAString( "¥pTotal time: " );
  278.         DrawAAString( timestr );
  279.         DrawAAString( "¥p 60ths/second" );
  280.     }
  281.     EndUpdate(window);
  282. }